package oa.hleast.xswl.service.venue.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import oa.hleast.xswl.mapper.CmsVenueMainMapper;
import oa.hleast.xswl.pojo.domain.CmsVenueMain;
import oa.hleast.xswl.pojo.vo.ManagerSignInVenuesVo;
import oa.hleast.xswl.service.venue.CmsVenueMainService;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author: 302
 * @date: 2021-07-05 15:14:29
 * @description: 场馆主表(CmsVenueMain)接口实现
 */
@Service("cmsVenueMainService")
@Slf4j
@Transactional
@AllArgsConstructor
public class CmsVenueMainServiceImpl extends ServiceImpl<CmsVenueMainMapper, CmsVenueMain> implements CmsVenueMainService {

    @Override
    public List<ManagerSignInVenuesVo> listByUserIdForManager(Long userId, Long managerUserId, Integer signInStatues, Integer reviewStatus) {
        return this.getBaseMapper().listByUserIdForManager(userId, managerUserId, signInStatues, reviewStatus);
    }

    @Override
    public Page<CmsVenueMain> findVenueVoList(Integer page, Integer limit, String venueName, Long departmentId) {
        LambdaQueryWrapper<CmsVenueMain> queryWrapper = new LambdaQueryWrapper<CmsVenueMain>()

                .orderByDesc(CmsVenueMain::getGmtModified)
                .orderByDesc(CmsVenueMain::getGmtCreate);

        if (StringUtils.isNotBlank(venueName)) {
            queryWrapper.like(StrUtil.isNotBlank(venueName), CmsVenueMain::getVenueName, venueName);

        }
        if (ObjectUtils.isNotEmpty(departmentId)) {
            queryWrapper.eq(CmsVenueMain::getDepartmentDictItemId, departmentId);
        }

        Page<CmsVenueMain> result = this.page(new Page<>(page, limit), queryWrapper);
        return result;
    }
}
